package falcon.server.processor;

import falcon.common.Errno;
import falcon.common.FalconHost;
import falcon.server.FalconProManager;

public final class FalconHostProcessor {

	public static void processAdd(FalconProManager manager, FalconProManager.Req req, String[] pa) {
		if (pa.length < 5) {
			req.errno = Errno.COM_ARGS_MISS;
			req.desc = "参数: pa.length < 5";
			return;
		}
		String cipher = pa[0];
		String host = pa[1];
		int port = Integer.parseInt(pa[2]);
		String user = pa[3];
		long timestamp = Long.parseLong(pa[4]);
		int errno = FalconHost.add(manager.getConfig(), cipher, host, port, user, timestamp);
		if (errno != Errno.SUCCESS) {
			req.desc = "添加主机信息失败";
		}
		req.errno = errno;
	}
	
	public static void processRemove(FalconProManager manager, FalconProManager.Req req, String[] pa) {
		if (pa.length < 5) {
			req.errno = Errno.COM_ARGS_MISS;
			req.desc = "参数: pa.length < 5";
			return;
		}
		String cipher = pa[0];
		String host = pa[1];
		int port = Integer.parseInt(pa[2]);
		String user = pa[3];
		long timestamp = Long.parseLong(pa[4]);
		int errno = FalconHost.remove(manager.getConfig(), cipher, host, port, user, timestamp);
		if (errno != Errno.SUCCESS) {
			req.desc = "移除主机信息失败";
		}
		req.errno = errno;
	}
}
